/* Contains the functions of the class: Complex */
#include "Complex.h"

double abs(Complex c2)
{
      /* Actually returns ABS_SQUARED ... */
  return c2.re*c2.re + c2.im*c2.im;
}


Complex Complex::operator+(Complex c2)
{
  Complex temp;

  temp.re = c2.re + re;
  temp.im = c2.im + im;

  return temp;
}

Complex Complex::operator+=(Complex c2)
{
  re += c2.re;
  im += c2.im;

  return *this;   // *this, is the object that generated the call
}

Complex Complex::operator-(Complex c2)
{
  Complex temp;
 
  temp.re = re - c2.re;
  temp.im = im - c2.im;

  return temp;
}

Complex Complex::operator-=(Complex c2)
{
  re -= c2.re;
  im -= c2.im;

  return *this;   // *this, is the object that generated the call
}

Complex Complex::operator*(Complex c2)
{
  Complex temp;
 
  temp.re = re*c2.re - im*c2.im;
  temp.im = im*c2.re + re*c2.im;

  return temp;
}

Complex Complex::operator*=(Complex c2)
{
  Complex temp;
 
  temp.re = re*c2.re - im*c2.im;
  temp.im = im*c2.re + re*c2.im;

  *this = temp;
  return *this;   // *this, is the object that generated the call
}
 
Complex Complex::operator/(Complex c2)
{
  Complex temp;

  temp.im = c2.re*c2.re + c2.im*c2.im;  // just storing the norm here
  temp.re = (re*c2.re + im*c2.im)/temp.im;
  temp.im = (im*c2.re - re*c2.im)/temp.im;

  return temp;
}

Complex Complex::operator/=(Complex c2)
{
  Complex temp;

  temp.im = c2.re*c2.re + c2.im*c2.im;  // just storing the norm here
  temp.re = (re*c2.re + im*c2.im)/temp.im;
  temp.im = (im*c2.re - re*c2.im)/temp.im;

  *this = temp;
  return *this;
}

Complex Complex::operator=(Complex c2)
{
  re = c2.re;
  im = c2.im;

  return *this;     // *this, is the object that generated the call
}


